package com.zero;

public class Main {

    public static void main(String[] args) {
	// java方法
        //调用函数
        printLLL();
        printLLL(10);
        int a = 15;
        int b = 20;
        int c = 0;
        c = max(a,b);
        System.out.println(c);
        double d1 = 23.4;
        double d2 = 44.6;
        double d3 = 0;
        d3 = max(d1,d2);
        System.out.println(d3);
        //实例化对象
        MyClass c1 = new MyClass();
        MyClass c2 = new MyClass(22);
        System.out.println(c1.x);
        System.out.println(c2.x);

        // 调用可变参数的方法
        printMax(34, 3, 3, 2, 56.5);
        printMax(new double[]{1, 2, 3});
    }
    //方法（无参无返回值）
    public static  void printLLL() {
        for (int i = 0; i < 4; i++) {
            System.out.print(i + "=>");
        }
        System.out.println();
    }

    //方法（有参无返回值）
    public static  void printLLL(int nub) {
        for (int i = 0; i < nub; i++) {
            System.out.print(i + "=>");
        }
        System.out.println();
    }

    //方法max（有参有返回值）
    public static int max(int num1, int num2) {
        int result;
        if (num1 > num2)
            result = num1;
        else
            result = num2;
        return result;
    }
    //方法重载
    public static double max(double num1, double num2) {
        if (num1 > num2)
            return num1;
        else
            return num2;
    }

    // 构造函数
    static class MyClass {
        int x;

        // 以下是构造函数
        MyClass() {
            x = 10;
        }
        MyClass(int age) {
            x = age;
        }
        protected void finalize() throws java.lang.Throwable {
            super.finalize();
            System.out.println("Cake Object " + x + "is disposed");
        }
    }
    //可变参数
    public static void printMax( double... numbers) {
        if (numbers.length == 0) {
            System.out.println("No argument passed");
            return;
        }

        double result = numbers[0];

        for (int i = 1; i <  numbers.length; i++){
            if (numbers[i] >  result) {
                result = numbers[i];
            }
        }
        System.out.println("The max value is " + result);
    }

}
